/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dicethrowing;


import java.util.Scanner;

/**
 *
 * @author CJ
 */
public class Main {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("Enter number of dice");
        int x = input.nextInt();

        double[] storage = generateSmart(new double[0], x);

        double total = Math.pow(6, x);

        for(int i = 0; i < storage.length; ++i)
        {
            if(storage[i] == 0)
                continue;
            System.out.println(i + 1 + " has a probabilty of: " + storage[i] + '/' + total);
        }
    }

    public static double[] generateSmart(double[] storage, int numDiceLeft){
        //Do we still need to roll dice?
        if(numDiceLeft <= 0)
            return storage;

        //Init first run array
        if(storage.length == 0)
        {
            storage = new double[6];
            for(int i = 0; i < storage.length; ++i)
                storage[i] = 1;
            return generateSmart(storage, numDiceLeft - 1);
        }

        //Else use shifting packages

        //Find the size of the array needed to be, eg the numbe of non zero memebers
        int size = 0;
        for(int i = 0;i<storage.length;++i)
            if(storage.length != 0)
                ++size;

        //Create result Array
        double[][] result = new double[size][storage.length + 6];

        //Build the layered rows
        int currentRow = 0;
        for(int i = 0;i < storage.length; ++i)
        {
            if(storage[i] == 0)
                continue;
            for(int x = 1; x < 7; ++x)
                result[currentRow][i + x] = storage[i];
            ++currentRow;
        }

        //Build the final return array

        double[] resultList = new double[storage.length + 6];
        for(int col = 0; col < result[0].length; ++col)
        {
            for(int row = 0; row < result.length; ++row)
            {
                resultList[col] += result[row][col];
            }
        }

        return generateSmart(resultList, numDiceLeft - 1);

    }
}
